﻿<?php
require_once('../../../config.php');
define('AJAX_SCRIPT', true);
global $DB;

$program=$_GET["program"];	//lấy mã chương trình đào tạo
$majors=$_GET["majors"];	//lấy mã chuyên ngành

$width = array('20px', '300px', '20px', '20px', '20px', '10px');
//neu dung sql thi phai co mdl_ truoc ten bang, con dung get_record
//Lấy các block thuộc chương trình đào tạo
$sql="SELECT * FROM mdl_block_of_knowledge ".
	  " WHERE program_id = '".$program."'";
$rs = $DB->get_records_sql($sql);

foreach ($rs as $r) {
	echo html_writer::tag('div', $r->bok_name, array('id'=>'Curriculum','class'=>'heading1'));
	echo html_writer::start_tag('table', array('align'=>'center'));
	echo html_writer::tag('th','Mã môn học', array('class'=>'headingblock header'));
	echo html_writer::tag('th','Tên môn học', array('class'=>'headingblock header'));
	echo html_writer::tag('th','Số tín chỉ', array('class'=>'headingblock header'));
	echo html_writer::tag('th','Số giờ lý thuyết', array('class'=>'headingblock header'));
	echo html_writer::tag('th','Số giờ thực hành', array('class'=>'headingblock header'));
	echo html_writer::tag('th','Mô tả', array('class'=>'headingblock header'));
	//Lấy danh sách môn học trong từng block
	$sql = "SELECT mdl_subject.id, mdl_subject.subject_id, subject_name_vn, subject_credit, subject_theory_hr, subject_practice_hr ".
			"FROM mdl_subject inner join  mdl_subject_block on mdl_subject_block.subject_id = mdl_subject.id". 
			" WHERE mdl_subject_block.blockofknowledge_id = ". $r->id;
	$subjects = $DB->get_records_sql($sql);
	foreach($subjects as $s){
		echo html_writer::start_tag('tr', array("style"=>"cursor:pointer;"));
		echo html_writer::tag('td',$s->subject_id, array("align"=>"center",'width'=>$width[0]));
		echo html_writer::tag('td',$s->subject_name_vn, array('width'=>$width[1], 'onmouseover'=>'toolTip(\'<strong>'.$s->subject_name_vn.'</strong><br>'.$s->abstract.'\', \'grey\', \'white\');', 'onmouseout'=>'toolTip();', 'onClick'=>'show_subject_info(\''.$s->id.'\');'));
		echo html_writer::tag('td',$s->subject_credit, array("align"=>"center",'width'=>$width[2]));
		echo html_writer::tag('td',$s->subject_theory_hr, array("align"=>"center",'width'=>$width[3]));
		echo html_writer::tag('td',$s->subject_practice_hr, array("align"=>"center",'width'=>$width[4]));
		echo html_writer::tag('td','<input type=checkbox id=subject name="subject" value="'.$s->id.'" />', array("align"=>"center",'width'=>$width[5]));
		echo html_writer::end_tag('tr');
	}
	echo html_writer::end_tag('table');
}	

//Lấy chuyên ngành có mã p
if(strcmp($majors,"")>0) {
	$majors= explode("*", $majors);	//tách các mã chuyên ngành từ chuỗi p và lưu mã chuyên ngành vào //mảng majors
	$n = count($majors);

	for($i=0; $i<$n; $i++) {

		$sql = "SELECT * ".
				" FROM mdl_major ".
				" WHERE mdl_major.id = ". $majors[$i];
		$major = $DB->get_record_sql($sql);
		echo html_writer::tag('div', 'Chuyên ngành: '.$major->major_name, array('class'=>'heading1'));

		//Lấy các block của chuyên ngành đào tạo p
		$sql = "SELECT mdl_block_of_knowledge.id, mdl_block_of_knowledge.bok_name  ".
				" FROM mdl_block_of_knowledge inner join mdl_major_block on mdl_block_of_knowledge.id = mdl_major_block.blockofknowledge_id".
				" WHERE mdl_major_block.major_id = ".$majors[$i];
			
		$rs = $DB->get_records_sql($sql);

		foreach ($rs as $r) {
			echo html_writer::tag('div', $r->bok_name, array('class'=>'heading2'));
			echo html_writer::start_tag('table', array('align'=>'center'));
			echo html_writer::tag('th','Mã môn học', array('class'=>'headingblock header'));
			echo html_writer::tag('th','Tên môn học', array('class'=>'headingblock header'));
			echo html_writer::tag('th','Số tín chỉ', array('class'=>'headingblock header'));
			echo html_writer::tag('th','Số giờ lý thuyết', array('class'=>'headingblock header'));
			echo html_writer::tag('th','Số giờ thực hành', array('class'=>'headingblock header'));
			echo html_writer::tag('th','Mô tả', array('class'=>'headingblock header'));
			
			//Lấy danh sách môn học trong từng block
			$sql = "SELECT mdl_subject.id, mdl_subject.subject_id, mdl_subject.subject_name_vn, mdl_subject.subject_credit, mdl_subject.subject_theory_hr, mdl_subject.subject_practice_hr ".
					"FROM mdl_subject inner join  mdl_subject_block on mdl_subject_block.subject_id = mdl_subject.id". 
					" WHERE mdl_subject_block.blockofknowledge_id = ". $r->id;
			$subjects = $DB->get_records_sql($sql);
			foreach($subjects as $s){
				echo html_writer::start_tag('tr', array("style"=>"cursor:pointer;"));
				echo html_writer::tag('td',$s->subject_id, array("align"=>"center",'width'=>$width[0]));
				echo html_writer::tag('td',$s->subject_name_vn, array('width'=>$width[1], 'onmouseover'=>'toolTip(\'<strong>'.$s->subject_name_vn.'</strong><br>'.$s->abstract.'\', \'black\', \'white\');', 'onmouseout'=>'toolTip();', 'onClick'=>'show_subject_info(\''.$s->id.'\');'));
				echo html_writer::tag('td',$s->subject_credit, array("align"=>"center",'width'=>$width[2]));
				echo html_writer::tag('td',$s->subject_theory_hr, array("align"=>"center",'width'=>$width[3]));
				echo html_writer::tag('td',$s->subject_practice_hr, array("align"=>"center",'width'=>$width[4]));
				echo html_writer::tag('td','<input type=checkbox name="subject" value="'.$s->id.'" />', array("align"=>"center",'width'=>$width[5]));
				echo html_writer::end_tag('tr');
			}
			echo html_writer::end_tag('table');
		}
	}	
}
 ?>